package com.sibu.yx.promotion.common.util;

import org.apache.commons.lang3.StringUtils;

/**
 * @author suzheng
 * @date 2021-07-08
 **/
public class StrReplaceUtil {
    public static String userNameReplaceWithStar(String userName) {
        if (StringUtils.isBlank(userName)) {
            return "*";
        }
        try {
            userName = userName.replaceAll("[\\ud800\\udc00-\\udbff\\udfff\\ud800-\\udfff]", "*");
            StringBuilder builder = new StringBuilder(userName);
            if (builder.length() > 2) {
                builder.replace(1, builder.length() - 1, "***");
            } else {
                builder.replace(0, builder.length() - 1, "***");
            }
            return builder.toString();
        } catch (Exception e) {
            return "***";
        }
    }
}
